

def sign_up(cli, app, images, keys, collection):
    """
    :param cli: 数据库连接
    :param app: 人脸分析工具
    :param images: 待分析得人脸图片列表
    :param keys: 唯一标识
    :param collection: 向量数据库名称
    :return: 运行结果
    """
    if len(images) != len(keys):
        return "人脸与主键数量无法对齐"
    data = []
    app.prepare(ctx_id=0, det_size=(640, 640))
    for i in range(len(images)):
        image = images[i]
        key = keys[i]
        faces = app.get(image)
        if not len(faces) == 1:
            return "该照片无法确定唯一人脸"
        else:
            face = faces[0]
            embedding = face.embedding
            data.append(
                {
                    "key": key,
                    "vector": embedding
                }
            )
    # print(data)
    cli.insert(
        collection_name=collection,
        data=data
    )
    return "success"
